package com.tojabo.sortObject;

import java.util.Comparator;

public class ComparatorFactory {

	public static Comparator<Object> getComparator(String sortkey){
		
		if(sortkey.equals("person")){
			return new PersonComparator();
		}
		
		return null;		
	}
			
}
class PersonComparator implements Comparator<Object>{

	@Override
	public int compare(Object o1, Object o2) {
		Person p1=(Person) o1;
		Person p2=(Person) o2;			
		int res = p1.getAge()-p2.getAge();			
		return res;
	}
	
}